package whu.cn.whushare.ui.main.my;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.text.format.DateUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.androidplus.ui.ToastManager;
import com.androidplus.util.StringUtil;
import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import whu.cn.whushare.R;
import whu.cn.whushare.bean.User;
import whu.cn.whushare.common.UserManager;
import whu.cn.whushare.net.Downloader;
import whu.cn.whushare.ui.common.BaseActivity;

/**
 * 文件名：BuildActivity
 * 描述：
 * 作者：胡平平
 * 时间：2015/1/6
 */
 @ViewMapping(id=R.layout.activity_build_group)         //获取BuildActivity的布局文件
public class BuildActivity  extends BaseActivity {
    @ViewMapping(id = R.id.build_type_radio)            //获取“创建类别”单选按钮组控件
    private RadioGroup mBuildTypeRadio;
    @ViewMapping(id = R.id.build_name)                  //获取“创建类别”文本显示框
    private EditText mBuildName;
    @ViewMapping(id = R.id.group_type_radio)            //获取“组群类别”单选按钮组控件
    private RadioGroup mGroupTypeRadio;
    @ViewMapping(id = R.id.email_to)                    //获取“邮箱”编辑框
    private EditText mEmailTo;
    public static final int BUILD_TYPE_GROUP =0;        //组
    public static final int BUILD_TYPE_CROWD =1;       //群

    private int mBuild_Type = BUILD_TYPE_GROUP;         //默认创建组

    @Override
    /**
     * 重写父类的方法，初始化当前activity
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initViewsAndActions();
    }

    /**
     * 方法名：initViewsAndActions()
     * 功 能：初始化页面控件及其动作
     */
    private void initViewsAndActions() {
        View root = ViewMappingUtil.mapView(this, this);
        getTopBar(root);
        mTopBar.title.setText(R.string.build_group_crowd);
        mTopBar.searchView.setVisibility(View.INVISIBLE);
        mTopBar.rightText.setVisibility(View.VISIBLE);
        mTopBar.rightText.setText(R.string.save);


        initRadio();
        initAction();
    }

    //对页面单选按钮进行初始化
    private void initRadio() {
        mBuildTypeRadio.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup group, int checkedId) {
                mBuild_Type = checkedId;
                if (checkedId == R.id.build_type_group) {
                    mTopBar.title.setText(R.string.build_group);
                } else {
                    mTopBar.title.setText(R.string.build_crowd);
                }
            }
        });
    }

    //对TopBar右部的"保存"按钮设置点击事件监听器，保存当前设置；
    private void initAction() {
        mTopBar.rightText.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        //创建一个Intent的实例
                        Intent intent = new Intent();
                        //设置从哪个activity启动哪个activity
                        intent.setClass(BuildActivity.this, BuildOkActivity.class);
                        //启动另一个activity
                        startActivity(intent);
            }
        });
    }
}

